refactor: host alias logic in wrapper#431
Merged
Conversation
sergiyvamz
reviewed
May 5, 2023
wrapper/src/main/java/software/amazon/jdbc/PluginServiceImpl.java
Outdated
Show resolved
Hide resolved
sergiyvamz
reviewed
May 5, 2023
sergiyvamz
reviewed
May 5, 2023
wrapper/src/main/java/software/amazon/jdbc/hostlistprovider/AuroraHostListProvider.java
Show resolved
Hide resolved
sergiyvamz
reviewed
May 5, 2023
| if (resultSet.next()) { | ||
| final String instanceName = resultSet.getString(1); | ||
| if (this.getCachedTopology() == null) { | ||
| final HostSpec host = new HostSpec(getHostEndpoint(instanceName)); |
Contributor
There was a problem hiding this comment.
Can we refresh topology with provided connection?
sergiyvamz
reviewed
May 5, 2023
wrapper/src/main/java/software/amazon/jdbc/hostlistprovider/AuroraHostListProvider.java
Outdated
Show resolved
Hide resolved
sergiyvamz
reviewed
May 5, 2023
|
|
||
| @Override | ||
| public HostSpec identifyConnection(Connection connection) throws SQLException { | ||
| return this.hostList.get(0); |
Contributor
There was a problem hiding this comment.
As discussed, we need to get sql from dialect, fetch node id, try to find it in topology.
sergiyvamz
reviewed
May 5, 2023
|
|
||
| if (conn != null) { | ||
| generateHostAliases(driverProtocol, conn, hostSpec); | ||
| hostSpec.resetAliases(); |
Contributor
There was a problem hiding this comment.
Why to reset? Some other plugin might already filled aliases for this host spec.
sergiyvamz
reviewed
May 5, 2023
wrapper/src/main/java/software/amazon/jdbc/plugin/efm/MonitorServiceImpl.java
Outdated
Show resolved
Hide resolved
… instead of instance endpoints during status checks.
sergiyvamz
reviewed
May 5, 2023
3a0b9c6 to
2997d86
Compare
sergiyvamz
reviewed
May 5, 2023
wrapper/src/main/java/software/amazon/jdbc/plugin/efm/HostMonitoringConnectionPlugin.java
Show resolved
Hide resolved
sergiyvamz
reviewed
May 5, 2023
| "MonitorServiceImpl.emptyAliasSet", | ||
| new Object[] {hostSpec})); | ||
| hostSpec.addAlias(hostSpec.asAlias()); | ||
| try { |
Contributor
There was a problem hiding this comment.
I think we can remove this entire try-catch block. We just rely on provided nodeKeys, and if they empty then we raise an exception.
acf1b5b to
d4c4586
Compare
d4c4586 to
9f49f77
Compare
This was referenced May 6, 2023
9f49f77 to
10f4a56
Compare
sergiyvamz
reviewed
May 6, 2023
| PluginServiceImpl.hostAliasNotFound=Can''t find any host by the following aliases: ''{0}''. | ||
| PluginServiceImpl.hostsChangelistEmpty=There are no changes in the hosts' availability. | ||
| PluginServiceImpl.failedToRetrieveHostPort=Could not retrieve Host:Port for connection. | ||
| PluginServiceImpl.nonEmptyAliases=fillAliases called when HostSpec already contains the following aliases: ''{0}''. Please reset HostSpec aliases before calling this method. |
Contributor
There was a problem hiding this comment.
"Please reset HostSpec aliases before calling this method."
I think it may mislead developers.
"Please reset HostSpec aliases if you need to re-fill them again." ?
e3b98ad to
c9a45a7
Compare
sergiyvamz
approved these changes
May 9, 2023
brycematheson1234
added a commit
to brycematheson1234/aws-advanced-jdbc-wrapper
that referenced
this pull request
Dec 16, 2025
Track connections by identityHashCode to avoid re-running alias queries when the same physical connection is reused (e.g., with internal pooling). - Add aliasedConnections set to track already-aliased connections - Only call resetAliases() + fillAliases() on first use of each connection - Clean up tracking on connection close/abort to prevent memory leaks - Add null-check for currentConnection in cleanup path - Add test for cleanup-and-reinitialize behavior This preserves the original PR aws#431 fix (fresh aliases for new physical connections to cluster endpoints) while avoiding 4-5 extra SQL queries per getConnection() when using HikariPooledConnectionProvider. Fixes performance regression with customEndpoint + initialConnection plugins.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Integration Test Run
https://github.com/Bit-Quill/aws-advanced-jdbc-wrapper/actions/runs/4920404497
Description
Issues fixed
Issue 1 Solution
Issue one is caused by the following check.
We need to remove the check for
PROMOTED_TO_WRITERIssue 2 & 3
Issues 2 and 3 are both caused by missing or incorrect instance endpoint in the hostspec's aliases. Issues 2 and 3 were originally fixed in #428 and #428, and the fixes contain a lot of similarities. This refactoring centralizes the logic populating the aliases and make it less error prone.
More information in respective tickets:
https://github.com/orgs/awslabs/projects/91/views/13?pane=issue&itemId=27190320
https://github.com/orgs/awslabs/projects/91/views/13?pane=issue&itemId=27190427
Additional Reviewers
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.